/-boot ...
BootController.ts
BootLayout.ts
StorageLoader.ts
boot.ts
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-storage
/-tests
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
x
100
93
100
99
100
99
100
99
100
97
100
87
        new storage.attached.dom.DetectStorage(this._storageElement, this._dom.documenOverride).
 
1
module teapo.boot {
2
3
  export class StorageLoader {
4
5
    private _domStorage: storage.attached.dom.LoadStorage;
6
7
    private _callbacks: StorageLoader.Callbacks = null; 
8
    
9
    private _indexedDBDetectCompleted = false;
10
    private _webSqlDetectCompleted = false;
11
    private _persistenceName: string = null;
12
    private _persistence: storage.attached.LoadStorage = null;
13
    
14
    constructor(
15
      private _dom: Dom,
16
      private _storageElement: HTMLElement,
17
      private _uniqueKey: string) {
18
19
      this._domStorage =
20
        new storage.attached.dom.DetectStorage(this._storageElement, this._dom.documenOverride).
21
            detectStorageSync();
22
23
    }
24
25
    loadStorage(callback: StorageLoader.Callbacks) {
26
27
      var detectIndexedDB = new storage.attached.indexedDB.DetectStorage();
28
      var detectWebSQL = new storage.attached.webSQL.DetectStorage();
29
30
      detectIndexedDB.detectStorageAsync(this._uniqueKey, (error, load) => {
31
        this._indexedDBDetectCompleted = true;
32
33
        if (error) {
34
          if (!this._webSqlDetectCompleted)
35
            return;
36
37
          this._detectCompleted();
38
        }
39
        else {
40
          this._persistence = load;
41
          this._persistenceName = 'indexedDB';
42
43
          this._detectCompleted();
44
        }
45
      });
46
47
      detectWebSQL.detectStorageAsync(this._uniqueKey, (error, load) => {
48
        this._webSqlDetectCompleted = true;
49
50
        if (this._indexedDBDetectCompleted) {
51
          return;
52
        }
53
54
        this._persistence = load;
55
        
56
      });
57
    }
58
59
    private _detectCompleted() {
60
      if (this._persistence) {
61
        // TODO: choose the source, do the migration, report
62
      }
63
      else {
64
        this._callbacks.detectionComplete('dom', this._domStorage.editedUTC, false);
65
      }
66
    }
67
68
  }
69
70
  export module StorageLoader {
71
72
    export interface Callbacks {
73
74
      detectionComplete(
75
        name: string,
76
        editedUTC: number,
77
        supportsPersistence: boolean): void;
78
79
      loadProgress(
80
        totalFileCount: number,
81
        lastLoadedFilename: string);
51:9